package com.joven.shelltest.controller;

import com.joven.shelltest.entity.SysUserModel;
import com.joven.shelltest.service.SysUserService;
import com.joven.shelltest.utils.clearandreloadcache.ClearAndReloadCache;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.cache.annotation.Cacheable;

/**
 * @Author wzj
 * @Date 2023-11-07 14:30
 **/
@RequestMapping("/redisClear")
@RestController
@RequiredArgsConstructor
public class ClearAndReloadCacheController {

    private final SysUserService sysUserService;

    @GetMapping("/get/{id}")
    @Cacheable(cacheNames = {"get"})
    public SysUserModel get(@PathVariable("id") Integer id){
        return sysUserService.getById(id);
    }

    @PostMapping("/updateData")
    @ClearAndReloadCache(name = "get method")
    public Boolean updateData(@RequestBody SysUserModel user){
        return sysUserService.updateById(user);
    }

    @PostMapping("/insert")
    public Boolean insert(@RequestBody SysUserModel user){
        return sysUserService.save(user);
    }

    @DeleteMapping("/delete/{id}")
    public Boolean delete(@PathVariable("id") Integer id){
        return sysUserService.removeById(id);
    }
}
